|
|
|
|
|
|
|
Add this code to the Data1_Error event and then recompile the program. Again, attempt to run two instances of this program. This time, when you attempt to start the second instance, you receive a similar message, after which the program exits safely. (See Figure 17.2.) |
|
|
|
|
|
|
|
|
Figure 17.2.
Trapping the locked database error. |
|
|
|
|
|
|
|
|
You can use table-level locking to secure a single table while you perform sensitive operations on the table. If you want to increase the sale price of all items in your inventory by five percent, for example, you open the table for exclusive use and then perform the update. After you close the table, other users can open it and see the new price list. Using table-level locking for an operation like this can help prevent users from writing sales orders that contain some records with the old price and some records with the new price. |
|
|
|
|
|
|
|
|
Now modify the MULTIUS1.VBP project to illustrate table-level locking. Reopen the project and set the Exclusive property of the data control to False. This setting allows other users to open the database while your program is running. Now set the RecordSource property to MasterTable and set the Options property to 3. Setting the Options property to 3 opens the Recordset with the DenyWrite (1) and DenyRead (2) options turned on. This prevents other programs from opening MasterTable while your program is running. |
|
|
|
|
|
|
|
|
Save and recompile the program. Start a copy of the executable version of the program. It runs without error. Now attempt to start a second copy of the same program. You see an error message telling you that the table could not be locked because it is in use elsewherethat is, by the first instance of the program (see Figure 17.3). |
|
|
|
|
|